<% layout('layout') -%>
<div class="page-header">
  <div class="page-title">
    <h2>招标信息总览</h2>
    <span>及时获取药品采购需求，掌握截止时间与保证金要求</span>
  </div>
  <% if (currentUser && currentUser.role === 'TENDERER') { %>
    <a class="btn" href="/tenders/new">+ 发布招标</a>
  <% } %>
</div>

<div class="table-wrapper">
  <table class="table">
    <thead>
      <tr>
        <th>项目编号</th>
        <th>药品名称</th>
        <th>制药单位</th>
        <th>包装要求</th>
        <th>总量</th>
        <th>截止日期</th>
        <th>投标保证金</th>
        <th>发布单位</th>
        <th style="width:260px">操作</th>
      </tr>
    </thead>
    <tbody>
      <% tenders.forEach(t => { %>
        <tr>
          <td><span class="tag tag-primary"><%= t.tender_code %></span></td>
          <td><strong><%= t.drug_name %></strong></td>
          <td><%= t.manufacturer %></td>
          <td><%= t.package_req || '—' %></td>
          <td><%= t.total_quantity %></td>
          <td><%= t.deadline %></td>
          <td>¥ <%= Number(t.deposit_amount).toFixed(2) %></td>
          <td><%= t.created_by_company || '—' %></td>
          <td>
            <div class="table-actions">
              <% if (currentUser && (currentUser.role === 'ADMIN' || currentUser.id === t.created_by)) { %>
                <a class="btn-outline" href="/tenders/<%= t.id %>/edit">编辑</a>
              <% } %>
              <a class="btn-secondary" href="/messages?tender_id=<%= t.id %>">留言交流</a>
            </div>
            <% if (currentUser && currentUser.role === 'BIDDER') { %>
              <form method="post" action="/bids" class="inline-form">
                <input type="hidden" name="tender_id" value="<%= t.id %>">
                <input name="product_batch" placeholder="产品批号">
                <input name="production_date" placeholder="生产日期">
                <input name="expiry_date" placeholder="有效期">
                <input name="total_amount" placeholder="投标总金额" required>
                <input name="deposit_paid_date" placeholder="保证金缴款日期">
                <button type="submit">提交投标</button>
              </form>
            <% } %>
          </td>
        </tr>
      <% }) %>
    </tbody>
  </table>
</div>


